#include <gtest/gtest.h>
#include "core/profile/default_profile.h"
#include "core/regions/end_point_provider.h"

using namespace aliyun;

TEST(core_profile, DefaultProfile) {
  EndpointProvider::SetDefaultEndpoints();

  DefaultProfile *default_profile = DefaultProfile::GetProfile("cn-hangzhou", "accessId", "accessSecret");
  ASSERT_NE(default_profile, (void*)0);
  ASSERT_STREQ("cn-hangzhou",default_profile->GetRegionId().c_str());
  ASSERT_STREQ("accessId",default_profile->GetCredential().GetAccessKeyId().c_str());
  ASSERT_STREQ("accessSecret",default_profile->GetCredential().GetAccessSecret().c_str());

  default_profile->AddEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com");
  const std::vector<Endpoint>& endpoints = default_profile->GetEndpoints();
  std::vector<Endpoint>::const_iterator iter_endpoint;
  for(iter_endpoint = endpoints.begin(); iter_endpoint != endpoints.end(); iter_endpoint++) {
    if("cn-hangzhou" == iter_endpoint->GetName()) {
      const std::vector<string>& region_ids = iter_endpoint->GetRegionIds();
      std::vector<string>::const_iterator iter_region_id;
      for(iter_region_id = region_ids.begin(); iter_region_id != region_ids.end(); iter_region_id++) {
        if("cn-hangzhou" == *iter_region_id) {
          break;
        }
      }
      ASSERT_NE(iter_region_id, region_ids.end());

      const std::vector<ProductDomain>& product_domains = iter_endpoint->GetProductDomains();
      ASSERT_GT(product_domains.size(), (size_t)0);
      std::vector<ProductDomain>::const_iterator iter_product_domain;
      for(iter_product_domain = product_domains.begin(); iter_product_domain != product_domains.end(); iter_product_domain++) {
        if("TestProduct" == iter_product_domain->GetProductName()) {
          ASSERT_STREQ("testproduct.aliyuncs.com",iter_product_domain->GetDomainName().c_str());
          break;
        }
      }
    }
  }
}


// end of file
